#include "material.h"

namespace MISystem
{
    MaterialStock::MaterialStock()
        : _stockQuantity(0)
    {}

    MaterialStock::MaterialStock(
        const QString& id,
        const QString& name,
        int quantity,
        const QString& location,
        const QDateTime& createTime)
        : _materialId(id)
        , _materialName(name)
        , _stockQuantity(quantity)
        , _location(location)
        , _createTime(createTime)
    {}

    QString MaterialStock::getMaterialId() const
    {
        return _materialId;
    }
    QString MaterialStock::getMaterialName() const
    {
        return _materialName;
    }
    int MaterialStock::getStockQuantity() const
    {
        return _stockQuantity;
    }
    QString MaterialStock::getLocation() const
    {
        return _location;
    }
    QDateTime MaterialStock::getCreateTime() const
    {
        return _createTime;
    }

    void MaterialStock::setMaterialName(const QString& name)
    {
        _materialName = name;
    }
    void MaterialStock::setStockQuantity(int quantity)
    {
        _stockQuantity = quantity;
    }
    void MaterialStock::setLocation(const QString& loc)
    {
        _location = loc;
    }

    QJsonObject MaterialStock::toJson() const {
        return {
            {"material_id", _materialId},
            {"material_name", _materialName},
            {"stock_quantity", _stockQuantity},
            {"location", _location},
            {"create_time", _createTime.toString(Qt::ISODate)}
        };
    }

    MaterialStock MaterialStock::fromJson(const QJsonObject& json) {
        MaterialStock ms;
        ms._materialId = json["material_id"].toString();
        ms._materialName = json["material_name"].toString();
        ms._stockQuantity = json["stock_quantity"].toInt();
        ms._location = json["location"].toString();
        ms._createTime = QDateTime::fromString(json["create_time"].toString(), Qt::ISODate);
        return ms;
    }
}